home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libimp
/
imptobw.c.z
/
imptobw.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
4KB
|
145 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: imptobw.c
*
* Description: Converts an SGI Image file from RGB to black and white (W).
*
* Uasge: imptobw inimage outimage
*
**************************************************************************/
#ident "$Revision: 1.1 $"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "imp.h"
/**************************************************************************
*
* Function: main
*
* Description: Program entry point
*
* Parameters:
* argc (I) - number of command line arguments
* argv (I) - command line arguments
*
* Return: 0 if no errors. 1 if errors.
*
**************************************************************************/
int main(int argc, char *argv[])
{
IMPImage *inImage, *outImage;
register int y, chan;
register int xsize, ysize, inNumChan;
short *row[3], *wrow;
char *pname;
/*
* Extract the program name
*/
pname = ((pname = strrchr(argv[0], '/')) == NULL) ? argv[0]: pname + 1;
/*
* Check the arg count
*/
if (argc < 3) {
fprintf(stderr, "Usage: %s inimage outimage\n", pname);
exit(1);
}
/*
* Open the input image
*/
if ((inImage = impOpen(argv[1], "r")) == NULL ) {
impPerror(pname);
exit(1);
}
xsize = impXSize(inImage);
ysize = impYSize(inImage);
inNumChan = impNumChannels(inImage);
for (chan = 0; chan < inNumChan; chan++)
row[chan] = (short*)malloc(xsize * sizeof(short));
wrow = (short*)malloc(xsize * sizeof(short));
/*
* Open the output image
*/
if ((outImage = impOpen(argv[2], "w",
impMakeRasterType(impRasterEncoding(inImage),
impRasterBPP(inImage)),
impDimension(inImage),
xsize, ysize, 1,
impImageType(inImage),
impName(inImage))) == NULL) {
impPerror(pname);
exit(1);
}
/*
* Convert the image. Note that if the image is already one
* channel just copy it.
*/
for (y = 0; y < ysize; y++) {
for (chan = 0; chan < inNumChan; chan++) {
if (impReadRow(inImage, row[chan], y, chan) < 0) {
impPerror(pname);
exit(1);
}
}
if (inNumChan > 1)
impRGBtoW(row[0], row[1], row[2], wrow, xsize);
else
wrow = row[0];
if (impWriteRow(outImage, wrow, y, 0) < 0) {
impPerror(pname);
exit(1);
}
}
/*
* Close up all images and free storage
*/
for (chan = 0; chan < inNumChan; chan++)
free(row[chan]);
free(wrow);
if (impClose(inImage) < 0) {
impPerror(pname);
exit(1);
}
if (impClose(outImage) < 0) {
impPerror(pname);
exit(1);
}
return 0;
}